package com.example.app2024.navigationview;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.app2024.R;
import com.google.android.material.navigation.NavigationView;

public class NaviActivity extends AppCompatActivity
{
      NavigationView navigationView;

      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
            super.onCreate(savedInstanceState);
            EdgeToEdge.enable(this);
            setContentView(R.layout.activity_navi);
            ViewCompat.setOnApplyWindowInsetsListener(
                    findViewById(R.id.main), (v, insets) -> {
                          Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                          v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
                          return insets;
                    });
            navigationView = findViewById(R.id.navi);
            navigationView.setItemIconTintList(null);  // 使菜单项可用

            View view1 = navigationView.getHeaderView(0);
            ImageView imageView = view1.findViewById(R.id.imageView);
            imageView.setOnClickListener(new View.OnClickListener()
            {
                  @Override
                  public void onClick(View v)
                  {
                        Toast.makeText(NaviActivity.this, "你占击了头部图象", Toast.LENGTH_LONG).show();
                  }
            });

            TextView textView = view1.findViewById(R.id.textView3333);

            navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener()
            {
                  @Override
                  public boolean onNavigationItemSelected(@NonNull MenuItem item)
                  {
                        Toast.makeText(NaviActivity.this, "你占击了菜单是 " +item.getTitle(), Toast.LENGTH_LONG).show();
                        return true;
                  }
            });
      }
}